/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the
 * GPL version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.prefs.util;

import org.digitalsoul.switchplugin.actions.Action;
import org.digitalsoul.switchplugin.matchers.Matcher;
import org.digitalsoul.switchplugin.model.Criteria;
import org.digitalsoul.switchplugin.model.IConfigSwitchItem;
import org.digitalsoul.switchplugin.model.SwitchItem;

import java.util.List;


public class ConfigurableItem {

    private IConfigSwitchItem item;

    public ConfigurableItem(IConfigSwitchItem item) {
        this.item = item;
    }
    
    public ConfigurableItem(String name) {
        this(new SwitchItem(name));
    }

    public Action removeAction(int index) {
        return item.getActions().remove(index);
    }
    
    public Matcher removeMatcher(int index) {
        return item.getMatchers().remove(index);
    }
    
    public String[] getActionDescriptions() {
        return getDescriptions(item.getActions());
    }

    public String[] getMatcherDescriptions() {
       return getDescriptions(item.getMatchers());
    }
    
    private String[] getDescriptions(List<? extends Criteria> list) {
        String[] descriptions = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            descriptions[i] = Printer.print(list.get(i));
        }
        return descriptions;
    }

    public void addMatcher(Matcher matcher) {
        item.getMatchers().add(matcher);
    }

    public void addAction(Action action) {
        item.getActions().add(action);
    }

    public String getName() {
        return item.getName();
    }

    public IConfigSwitchItem getSwitchItem() {
        return item;
    }

    public void addAction(Action action, int index) {
        item.getActions().add(index, action);
    }
}
